package com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ExceptionCast;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.util.CacheUtil;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.SmsAssetCategoryManagement;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.SmsAssetFixedStorage;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.SmsAssetProcess;
import com.xyht.sca_s.student_manage_system.modules.asset.entity.SmsAssetProcessDetail;
import com.xyht.sca_s.student_manage_system.modules.asset.mapper.SmsAssetCategoryManagementMapper;
import com.xyht.sca_s.student_manage_system.modules.asset.mapper.SmsAssetFixedStorageMapper;
import com.xyht.sca_s.student_manage_system.modules.asset.mapper.SmsAssetProcessDetailMapper;
import com.xyht.sca_s.student_manage_system.modules.asset.mapper.SmsAssetProcessMapper;
import com.xyht.sca_s.student_manage_system.modules.assetFixedBorrow.entity.SmsAssetMyAssets;
import com.xyht.sca_s.student_manage_system.modules.assetFixedBorrow.entity.vo.SmsAssetMyAssetsVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedBorrow.mapper.SmsAssetMyAssetsMapper;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.SmsAssetFixedRepairApply;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.SmsAssetFixedRepairApplyGoods;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.SmsAssetFixedRepairApplyGoodsDetail;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.SmsAssetFixedRepairApplyProcessDetail;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.dto.SmsAssetFixedRepairApplyDTO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.dto.SmsAssetFixedRepairApplyGoodsDTO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.dto.SmsAssetFixedRepairApplyMPJDTO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.dto.SmsAssetFixedRepairApplyProcessDetailDTO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.vo.SmsAssetFixedRepairApplyAllowVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.vo.SmsAssetFixedRepairApplyProcessDetailVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.entity.vo.SmsAssetFixedRepairApplyVO;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.mapper.*;
import com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.service.SmsAssetFixedRepairApplyService;
import com.xyht.sca_s.student_manage_system.modules.newTips.myEnum.AppTypeEnum;
import com.xyht.sca_s.student_manage_system.modules.newTips.myEnum.RangeTypeEnum;
import com.xyht.sca_s.student_manage_system.modules.newTips.myEnum.TipsTypeEnum;
import com.xyht.sca_s.student_manage_system.modules.newTips.util.NewTipsUtil;
import com.xyht.sca_s.student_manage_system.modules.user.entity.SmsUser;
import com.xyht.sca_s.student_manage_system.modules.user.entity.resp.SmsSearchUserResp;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import static com.xyht.sca_s.student_manage_system.common.util.ParamCheckUtil.isNullOrEmpty;
import static com.xyht.sca_s.student_manage_system.modules.asset.constant.AssetBooleanConstant.ASSET_BOOLEAN_FALSE;
import static com.xyht.sca_s.student_manage_system.modules.asset.constant.AssetBooleanConstant.ASSET_BOOLEAN_TRUE;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedBorrow.constant.AssetStatusConstant.ASSET_STATUS_IN_STORAGE;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetAllowStatusConstant.*;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetApplyTypeConstant.*;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetBooleanConstant.ASSET_REPAIR_BOOLEAN_TRUE;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetObjectTypeConstant.ASSET_REPAIR_OBJECT_TYPE_PERSON;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetObjectTypeConstant.ASSET_REPAIR_OBJECT_TYPE_ROLE;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetProcessTypeConstant.ASSET_PROCESS_TYPE_FIXED_REPAIR_STORAGE;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetStatusConstant.ASSET_STATUS_BORROW;
import static com.xyht.sca_s.student_manage_system.modules.assetFixedRepair.constant.AssetStatusConstant.ASSET_STATUS_REPAIR;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author XYHT
 * @since 2023-06-05
 */
@Service
public class SmsAssetFixedRepairApplyServiceImpl extends ServiceImpl<SmsAssetFixedRepairApplyMapper, SmsAssetFixedRepairApply> implements SmsAssetFixedRepairApplyService {
    @Autowired
    SmsAssetFixedRepairApplyMapper smsAssetFixedRepairApplyMapper;
    @Autowired
    SmsAssetProcessDetailMapper smsAssetProcessDetailMapper;
    @Autowired
    SmsAssetCategoryManagementMapper smsAssetCategoryManagementMapper;
    @Autowired
    SmsAssetFixedRepairApplyGoodsMapper smsAssetFixedRepairApplyGoodsMapper;
    @Autowired
    SmsAssetProcessMapper smsAssetProcessMapper;
    @Autowired
    SmsAssetFixedRepairApplyProcessDetailMapper smsAssetFixedRepairApplyProcessDetailMapper;
    @Autowired
    NewTipsUtil newTipsUtil;
    @Autowired
    CacheUtil cacheUtil;
    @Autowired
    SmsAssetFixedRepairApplyProcessDetailMPJMapper smsAssetFixedRepairApplyProcessDetailMPJMapper;
    @Autowired
    SmsAssetFixedRepairApplyGoodsDetailMapper smsAssetFixedRepairApplyGoodsDetailMapper;
    @Autowired
    SmsAssetFixedStorageMapper smsAssetFixedStorageMapper;
    @Autowired
    SmsAssetMyAssetsMapper smsAssetMyAssetsMapper;


    @Transactional
    @Override
    public ResponseResult addAssetFixedRepair(SmsAssetFixedRepairApplyVO applyVO, String user_id) {

        if(isNullOrEmpty(applyVO.getAssetList())||applyVO.getAssetList().size()<1){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        for(SmsAssetMyAssetsVO myAssetsVO:applyVO.getAssetList()){
            QueryWrapper<SmsAssetMyAssets> queryWrapper  = new QueryWrapper<>();
            queryWrapper.lambda().eq(SmsAssetMyAssets::getUserId,user_id)
                    .eq(SmsAssetMyAssets::getAssetId,myAssetsVO.getAssetId())
                    .eq(SmsAssetMyAssets::getMyAssetStatus,ASSET_STATUS_BORROW);
            SmsAssetMyAssets smsAssetMyAssets = smsAssetMyAssetsMapper.selectOne(queryWrapper);
            if(isNullOrEmpty(smsAssetMyAssets)||smsAssetMyAssets.getId()==null){
                return CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_NOT_EXIST);
            }


        }

        if(isNullOrEmpty(applyVO.getApplyPerson())||isNullOrEmpty(applyVO.getApplyName())
        ||isNullOrEmpty(applyVO.getApplyRemark())||isNullOrEmpty(applyVO.getApplyRepairQuestion())
        ||isNullOrEmpty(applyVO.getApplyDepartment())
        ||isNullOrEmpty(applyVO.getApplyPic())){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }

        SmsAssetProcess originProcess = smsAssetProcessMapper.selectOne(new QueryWrapper<SmsAssetProcess>()
                .lambda()
                .eq(SmsAssetProcess::getProcessType, ASSET_PROCESS_TYPE_FIXED_REPAIR_STORAGE));
        List<SmsAssetProcessDetail> fillProcessList =
                smsAssetProcessDetailMapper.selectList(new QueryWrapper<SmsAssetProcessDetail>()
                        .lambda()
                        .eq(SmsAssetProcessDetail::getProcessId,originProcess.getId())
                        .eq(SmsAssetProcessDetail::getProcessDetailIsApplicantEdit, true)
                        .eq(SmsAssetProcessDetail::getProcessDetailIsUse, true)
                        .orderByAsc(SmsAssetProcessDetail::getProcessDetailSort));
        if (fillProcessList != null && fillProcessList.size() > 0) {
            if (applyVO.getProcessList() == null || applyVO.getProcessList().size() < 1) {
                return CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_ALLOW_USER_NOT_SETTING);
            }
            //判断申请人是否将全部需要编辑流程填写
            if (applyVO.getProcessList() == null || applyVO.getProcessList().size() < 1) {
                return CommonResult.failed(CommonCodeEnum.ASSET_BORROW_ALLOW_USER_NOT_SETTING);
            }
            //判断申请人是否将全部需要编辑流程填写
            List<SmsAssetProcessDetail> filterList = fillProcessList
                    .stream()
                    .filter(process -> {
                                List<SmsAssetFixedRepairApplyProcessDetailVO> result = applyVO.getProcessList()
                                        .stream()
                                        .filter(fillProcess -> fillProcess.getProcessDetailId().equals(process.getId()))
                                        .collect(Collectors.toList());
                                //匹配的去除  未匹配的留下
                                if (result.size() > 0) {
                                    return false;
                                } else {
                                    return true;
                                }
                            }
                    )
                    .collect(Collectors.toList());
            if (filterList.size() > 0) {
                return CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_ALLOW_PROCESS_NOT_FILL);
            }
        }
            //创建申请表
            SmsAssetFixedRepairApply smsAssetFixedrepairApply = new SmsAssetFixedRepairApply();
            BeanUtils.copyProperties(applyVO, smsAssetFixedrepairApply);
            smsAssetFixedrepairApply.setApplyUserId(user_id);
            smsAssetFixedrepairApply.setAssetId(applyVO.getAssetId());
            smsAssetFixedrepairApply.setAllowStatus(ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW);
            smsAssetFixedRepairApplyMapper.insert(smsAssetFixedrepairApply);
            if (isNullOrEmpty(smsAssetFixedrepairApply.getId())) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.FAIL));
            }
            String apply_id = smsAssetFixedrepairApply.getId();

        for(SmsAssetMyAssetsVO myAssetsVO:applyVO.getAssetList()){
            SmsAssetFixedRepairApplyGoodsDetail goodsDetail = new SmsAssetFixedRepairApplyGoodsDetail();
            goodsDetail.setAssetId(myAssetsVO.getAssetId());
            goodsDetail.setApplyId(apply_id);
            smsAssetFixedRepairApplyGoodsDetailMapper.insert(goodsDetail);

            QueryWrapper<SmsAssetMyAssets> queryWrapper  = new QueryWrapper<>();
            queryWrapper.lambda().eq(SmsAssetMyAssets::getUserId,user_id)
                    .eq(SmsAssetMyAssets::getAssetId,myAssetsVO.getAssetId())
                    .eq(SmsAssetMyAssets::getMyAssetStatus,ASSET_STATUS_BORROW);
            SmsAssetMyAssets smsAssetMyAssets = new SmsAssetMyAssets();
            smsAssetMyAssets.setMyAssetStatus(ASSET_STATUS_REPAIR);
            smsAssetMyAssetsMapper.update(smsAssetMyAssets,queryWrapper);

        }

            //创建维修申请物品记录

            //创建审批流程
            //主流程

            //流程节点
            List<SmsAssetProcessDetail> originProcessDetailList =
                    smsAssetProcessDetailMapper.selectList(new QueryWrapper<SmsAssetProcessDetail>()
                            .lambda()
                            .eq(SmsAssetProcessDetail::getProcessDetailIsUse, ASSET_BOOLEAN_TRUE)
                            .eq(SmsAssetProcessDetail::getProcessId, originProcess.getId())
                            .orderByAsc(SmsAssetProcessDetail::getProcessDetailSort));
            if (originProcessDetailList == null || originProcessDetailList.size() < 1) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_PROCESS_NOT_SETTING));
            }

            int sort = 1;
            for (SmsAssetProcessDetail process : originProcessDetailList) {
                //判断管理员是否配置初始流程
                if (process.getProcessDetailIsApplicantEdit().equals(ASSET_BOOLEAN_FALSE)) {
                    if (isNullOrEmpty(process.getProcessDetailObjectId()) || isNullOrEmpty(process.getProcessDetailObjectType())) {
                        ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_PROCESS_NOT_SETTING));
                    }
                }
                SmsAssetFixedRepairApplyProcessDetail addDetail =
                        new SmsAssetFixedRepairApplyProcessDetail();

                addDetail.setApplyId(apply_id);
                addDetail.setProcessDetailId(process.getId());
                addDetail.setProcessDetailIsSign(process.getProcessDetailIsSign());
                addDetail.setProcessDetailIsStamp(process.getProcessDetailIsStamp());
                addDetail.setProcessDetailName(process.getProcessDetailName());
                addDetail.setProcessDetailStatus(ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW);
                addDetail.setProcessDetailIsApplicantEdit(process.getProcessDetailIsApplicantEdit());
                addDetail.setProcessDetailSort(sort++);

                //申请人可编辑流程
                if (process.getProcessDetailIsApplicantEdit().equals(ASSET_BOOLEAN_TRUE)) {
                    List<SmsAssetFixedRepairApplyProcessDetailVO> filterList = applyVO.getProcessList()
                            .stream()
                            .filter(fillProcess -> fillProcess.getProcessDetailId().equals(process.getId()))
                            .collect(Collectors.toList());
                    if (filterList.size() < 1) {
                        ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_ALLOW_PROCESS_NOT_FILL));
                    }
                    SmsAssetFixedRepairApplyProcessDetailVO fillProcessReq = filterList.get(0);

                    if (isNullOrEmpty(fillProcessReq.getProcessDetailObjectId())) {
                        ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
                    }
                    addDetail.setProcessDetailObjectId(fillProcessReq.getProcessDetailObjectId());
                    addDetail.setProcessDetailObjectType(fillProcessReq.getProcessDetailObjectType());
                } else {
                    addDetail.setProcessDetailObjectId(process.getProcessDetailObjectId());
                    addDetail.setProcessDetailObjectType(process.getProcessDetailObjectType());
                }

                smsAssetFixedRepairApplyProcessDetailMapper.insert(addDetail);

                SmsAssetFixedRepairApplyProcessDetail addDetail1 =
                        new SmsAssetFixedRepairApplyProcessDetail();

                addDetail1.setApplyId(apply_id);
                addDetail1.setProcessDetailIsSign(0);
                addDetail1.setProcessDetailIsStamp(0);
                addDetail1.setProcessDetailName("维修最终确认人");
                addDetail1.setProcessDetailObjectType(ASSET_REPAIR_OBJECT_TYPE_PERSON);
                addDetail1.setProcessDetailObjectId(user_id);
                addDetail1.setProcessDetailStatus(ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW);
                addDetail1.setProcessDetailIsApplicantEdit(0);
                addDetail1.setProcessDetailSort(sort);
                smsAssetFixedRepairApplyProcessDetailMapper.insert(addDetail1);

            }

        //消息通知
        //通知流程第一个节点
        SmsAssetFixedRepairApplyProcessDetail firstDetail =
                smsAssetFixedRepairApplyProcessDetailMapper.selectOne(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                        .lambda()
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, apply_id)
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailSort, 1)
                        .orderByAsc(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailSort));
        RangeTypeEnum rangeTypeEnum;
        if(firstDetail.getProcessDetailIsApplicantEdit().equals(1)){
            rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_PERSON;
        }else {
            if (firstDetail.getProcessDetailObjectType() == ASSET_REPAIR_OBJECT_TYPE_PERSON) {
                rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_PERSON;
            } else {
                rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_ROLE;
            }
        }
        List<String> rangeList = new ArrayList<>();
        rangeList.add(firstDetail.getProcessDetailObjectId());

        newTipsUtil.addNewTips(TipsTypeEnum.TIPS_TYPE_ENUM_ALLOW,
                user_id,
                rangeTypeEnum,
                rangeList,
                AppTypeEnum.APP_TYPE_ENUM_ASSET,
                apply_id,
                firstDetail.getId());
        return CommonResult.success();
    }

    @Transactional
    @Override
    public ResponseResult cancelAssetFixedRepair(SmsAssetFixedRepairApplyVO cancelVO, String user_id) {
        if(isNullOrEmpty(cancelVO.getApplyId())){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        SmsAssetFixedRepairApply assetRepairApply = smsAssetFixedRepairApplyMapper.selectOne(new QueryWrapper<SmsAssetFixedRepairApply>()
        .lambda()
        .eq(SmsAssetFixedRepairApply::getId,cancelVO.getApplyId())
        .eq(SmsAssetFixedRepairApply::getApplyUserId,user_id));
        if(assetRepairApply==null){
            return CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_APPLY_NOT_EXIST);
        }
        if (assetRepairApply.getAllowStatus() != ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_CANCEL_FAIL_ALLOWED));
        }
        //判断是否审批中
        List<SmsAssetFixedRepairApplyProcessDetail> processDetailList =
                smsAssetFixedRepairApplyProcessDetailMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                        .lambda()
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, cancelVO.getApplyId())
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailStatus, ASSET_REPAIR_ALLOW_STATUS_PASS));
        if (processDetailList.size() > 0 && processDetailList != null) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_CANCEL_FAIL_ALLOWED));
        }
        //撤销申请
        SmsAssetFixedRepairApply cancelRepairApply = new SmsAssetFixedRepairApply();
        cancelRepairApply.setId(cancelVO.getApplyId());
        cancelRepairApply.setAllowStatus(ASSET_REPAIR_ALLOW_STATUS_CANCEL);
        cancelRepairApply.setEndTime(new Date());
        smsAssetFixedRepairApplyMapper.updateById(cancelRepairApply);

        QueryWrapper<SmsAssetFixedRepairApplyGoodsDetail> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(SmsAssetFixedRepairApplyGoodsDetail::getApplyId,cancelVO.getApplyId());
        List<SmsAssetFixedRepairApplyGoodsDetail> list = smsAssetFixedRepairApplyGoodsDetailMapper.selectList(queryWrapper);
        if(!isNullOrEmpty(list)||list.size()>0){
            for(SmsAssetFixedRepairApplyGoodsDetail goodsDetail:list){
                QueryWrapper<SmsAssetMyAssets> queryWrapper1  = new QueryWrapper<>();
                queryWrapper1.lambda().eq(SmsAssetMyAssets::getUserId,user_id)
                        .eq(SmsAssetMyAssets::getAssetId,goodsDetail.getAssetId())
                        .eq(SmsAssetMyAssets::getMyAssetStatus,ASSET_STATUS_REPAIR);
                SmsAssetMyAssets smsAssetMyAssets = new SmsAssetMyAssets();
                smsAssetMyAssets.setMyAssetStatus(ASSET_STATUS_BORROW);
                smsAssetMyAssetsMapper.update(smsAssetMyAssets,queryWrapper1);

            }
        }

        //修改节点状态
        SmsAssetFixedRepairApplyProcessDetail cancelProcessDetail = new SmsAssetFixedRepairApplyProcessDetail();
        cancelProcessDetail.setProcessDetailStatus(ASSET_REPAIR_ALLOW_STATUS_CANCEL);
        smsAssetFixedRepairApplyProcessDetailMapper.update(cancelProcessDetail, new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                .lambda()
                .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, cancelVO.getApplyId()));
        //消息通知
        newTipsUtil.cancelFinishTips(cancelVO.getApplyId());
        return CommonResult.success();
    }

    @Transactional
    @Override
    public ResponseResult assetFixedRepairList(Integer pageSize, Integer pageNum, Integer apply_type, String user_id) {
        if(isNullOrEmpty(apply_type)){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        List<SmsAssetFixedRepairApplyDTO> respList = new ArrayList<>();
        int total = 0;
        //查看已发起
        if (apply_type == ASSET_REPAIR_APPLY_TYPE_APPLY) {
            Page<SmsAssetFixedRepairApply> page = new Page<>(pageNum, pageSize);
            QueryWrapper<SmsAssetFixedRepairApply> queryWrapper = new QueryWrapper<>();
            queryWrapper.lambda().eq(SmsAssetFixedRepairApply::getApplyUserId, user_id);
            smsAssetFixedRepairApplyMapper.selectPage(page, queryWrapper);
            respList = page.getRecords()
                    .stream()
                    .map(apply -> {
                        SmsAssetFixedRepairApplyDTO repairApplyDTO =
                                new SmsAssetFixedRepairApplyDTO();
                        BeanUtils.copyProperties(apply, repairApplyDTO);
                        repairApplyDTO.setApplyId(apply.getId());
                        SmsUser smsUser = cacheUtil.getUserInfo(apply.getApplyUserId());
                        SmsSearchUserResp userResp = new SmsSearchUserResp();
                        if (!isNullOrEmpty(smsUser)) {
                            BeanUtils.copyProperties(smsUser, userResp);
                        }
                        repairApplyDTO.setApplyUserInfo(userResp);
                        return repairApplyDTO;
                    })
                    .collect(Collectors.toList());
        }
        //查看已办类型
        else if (apply_type == ASSET_REPAIR_APPLY_TYPE_ALLOWED) {
            Page<SmsAssetFixedRepairApplyMPJDTO> page = new Page<>(pageNum, pageSize);
            MPJLambdaWrapper<SmsAssetFixedRepairApplyProcessDetail> mpjLambdaWrapper = new MPJLambdaWrapper<>();
            mpjLambdaWrapper.selectAll(SmsAssetFixedRepairApplyProcessDetail.class)
                    .selectAll(SmsAssetFixedRepairApply.class)
                    .selectAs(SmsAssetFixedRepairApply::getCreateTime, "applyCreateTime")
                    .selectAs(SmsAssetFixedRepairApplyProcessDetail::getId, "detailId")
                    .leftJoin(SmsAssetFixedRepairApply.class, SmsAssetFixedRepairApply::getId, SmsAssetFixedRepairApplyProcessDetail::getApplyId)
                    .eq(SmsAssetFixedRepairApplyProcessDetail::getAllowUserId, user_id)
                    //.orderByDesc(SmsAssetFixedRepairApply::getCreateTime)
                    .orderByDesc(SmsAssetFixedRepairApplyProcessDetail::getEndTime);
            smsAssetFixedRepairApplyProcessDetailMPJMapper.selectJoinPage(page, SmsAssetFixedRepairApplyMPJDTO.class, mpjLambdaWrapper);
            respList = page.getRecords()
                    .stream()
                    .map(smsMPJResp -> {
                        SmsAssetFixedRepairApplyDTO applyResp = new SmsAssetFixedRepairApplyDTO();
                        BeanUtils.copyProperties(smsMPJResp, applyResp);
                        applyResp.setCreateTime(smsMPJResp.getApplyCreateTime());
                        applyResp.setEndTime(smsMPJResp.getEndTime());
                        SmsUser smsUser = cacheUtil.getUserInfo(smsMPJResp.getAllowUserId());
                        SmsSearchUserResp allowUserResp = new SmsSearchUserResp();
                        if (!isNullOrEmpty(smsUser)) {
                            BeanUtils.copyProperties(smsUser, allowUserResp);
                        }
                        applyResp.setApplyUserInfo(allowUserResp);

                        return applyResp;
                    }).collect(Collectors.toList());
            total = (int) page.getTotal();
        }
        else if (apply_type == ASSET_REPAIR_APPLY_TYPE_ALLOW_WAIT_ME) {
            List<String> roleList = cacheUtil.getRoleList(user_id);
            //获取所有待审批申请流程节点
            List<SmsAssetFixedRepairApplyProcessDetail> allDetailList =
                    smsAssetFixedRepairApplyProcessDetailMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                            .lambda()
                            .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailStatus, ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW));

            List<SmsAssetFixedRepairApplyProcessDetail> filterDetailList = allDetailList.stream()
                    .filter(detail -> {
                        if(detail.getProcessDetailIsApplicantEdit().equals(1)){
                            if (!detail.getProcessDetailObjectId().equals(user_id)) {
                                return false;
                            }
                        }else{
                            if (detail.getProcessDetailObjectType() == ASSET_REPAIR_OBJECT_TYPE_PERSON) {
                                if (!detail.getProcessDetailObjectId().equals(user_id)) {
                                    return false;
                                }
                            } else {
                                List<String> filterRoleList = roleList.stream().filter(role -> role.equals(detail.getProcessDetailObjectId())).collect(Collectors.toList());
                                if (filterRoleList.size() < 1) {
                                    return false;
                                }
                            }
                        }


                        if (detail.getProcessDetailSort().equals(1)) {
                            return true;
                        }
                        //判断上一个流程节点是否完成
                        SmsAssetFixedRepairApplyProcessDetail preDetail =
                                smsAssetFixedRepairApplyProcessDetailMapper.selectOne(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                                        .lambda()
                                        .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, detail.getApplyId())
                                        .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailSort, detail.getProcessDetailSort() - 1)
                                        .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailStatus, ASSET_REPAIR_ALLOW_STATUS_PASS));
                        if (preDetail == null || isNullOrEmpty(preDetail.getId())) {
                            return false;
                        }
                        return true;
                    })
                    .collect(Collectors.toList());
            if (filterDetailList.size() > 0) {
                List<String> detailIDList = filterDetailList.stream()
                        .map(SmsAssetFixedRepairApplyProcessDetail::getId)
                        .collect(Collectors.toList());

                Page<SmsAssetFixedRepairApplyMPJDTO> page = new Page<>(pageNum, pageSize);
                MPJLambdaWrapper<SmsAssetFixedRepairApplyProcessDetail> mpjLambdaWrapper = new MPJLambdaWrapper<>();
                mpjLambdaWrapper.selectAll(SmsAssetFixedRepairApplyProcessDetail.class)
                        .selectAll(SmsAssetFixedRepairApply.class)
                        .selectAs(SmsAssetFixedRepairApply::getCreateTime, "applyCreateTime")
                        .selectAs(SmsAssetFixedRepairApplyProcessDetail::getId, "detailId")
                        .leftJoin(SmsAssetFixedRepairApply.class, SmsAssetFixedRepairApply::getId, SmsAssetFixedRepairApplyProcessDetail::getApplyId)
                        .in(SmsAssetFixedRepairApplyProcessDetail::getId, detailIDList)
                        .orderByDesc(SmsAssetFixedRepairApply::getCreateTime)
                        .orderByDesc(SmsAssetFixedRepairApplyProcessDetail::getCreateTime)
                ;
                smsAssetFixedRepairApplyProcessDetailMPJMapper.selectJoinPage(page, SmsAssetFixedRepairApplyMPJDTO.class, mpjLambdaWrapper);

                respList = page.getRecords()
                        .stream()
                        .map(smsApplyMPJResp -> {
                            SmsAssetFixedRepairApplyDTO applyResp = new SmsAssetFixedRepairApplyDTO();
                            BeanUtils.copyProperties(smsApplyMPJResp, applyResp);
                            applyResp.setCreateTime(smsApplyMPJResp.getApplyCreateTime());

                            SmsUser applyUser = cacheUtil.getUserInfo(smsApplyMPJResp.getApplyUserId());
                            SmsSearchUserResp smsExamineUserResp = new SmsSearchUserResp();
                            if (applyUser != null) {
                                BeanUtils.copyProperties(applyUser, smsExamineUserResp);
                            }
                            applyResp.setApplyUserInfo(smsExamineUserResp);

                            return applyResp;
                        })
                        .collect(Collectors.toList());
                total = (int) page.getTotal();
            }
        }
        return CommonResult.success(respList, total);
    }

    @Transactional
    @Override
    public ResponseResult assetFixedRepairDetail(String apply_id, String user_id) {
        if(isNullOrEmpty(apply_id)){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        SmsAssetFixedRepairApply repairApply = smsAssetFixedRepairApplyMapper.selectById(apply_id);
        if(repairApply==null||isNullOrEmpty(repairApply.getId())){
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_APPLY_NOT_EXIST));
        }
        SmsAssetFixedRepairApplyDTO repairApplyDTO = new SmsAssetFixedRepairApplyDTO();
        BeanUtils.copyProperties(repairApply,repairApplyDTO);
        repairApplyDTO.setApplyId(repairApply.getId());
        SmsUser smsUser = cacheUtil.getUserInfo(repairApplyDTO.getApplyUserId());
        SmsSearchUserResp smsUserResp = new SmsSearchUserResp();
        if (smsUser != null) {
            BeanUtils.copyProperties(smsUser, smsUserResp);
        }
        repairApplyDTO.setApplyUserInfo(smsUserResp);

        //封装流程节点
        List<SmsAssetFixedRepairApplyProcessDetailDTO> detailList =
                smsAssetFixedRepairApplyProcessDetailMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                        .lambda()
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, apply_id)
                        .orderByAsc(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailSort))
                        .stream()
                        .map(detail -> {
                            SmsAssetFixedRepairApplyProcessDetailDTO detailDTO = new SmsAssetFixedRepairApplyProcessDetailDTO();
                            BeanUtils.copyProperties(detail, detailDTO);
                            if (!isNullOrEmpty(detailDTO.getAllowUserId())) {
                                SmsUser userInfo = cacheUtil.getUserInfo(detailDTO.getAllowUserId());
                                SmsSearchUserResp smsSearchUserResp = new SmsSearchUserResp();
                                if (userInfo != null) {
                                    BeanUtils.copyProperties(userInfo, smsSearchUserResp);
                                }
                                detailDTO.setAllowUserInfo(smsSearchUserResp);
                            }
                            return detailDTO;
                        })
                        .collect(Collectors.toList());
        //封装物品信息
        List<SmsAssetFixedRepairApplyGoodsDTO> goodsList =
                smsAssetFixedRepairApplyGoodsMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyGoods>()
                        .lambda()
                        .eq(SmsAssetFixedRepairApplyGoods::getApplyId, apply_id))
                        .stream()
                        .map(goods -> {
                            SmsAssetFixedRepairApplyGoodsDTO goodsDTO = new SmsAssetFixedRepairApplyGoodsDTO();
                            BeanUtils.copyProperties(goods, goodsDTO);

                            List<String> assetPreIdList = smsAssetFixedRepairApplyGoodsDetailMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyGoodsDetail>()
                                    .lambda()
                                    .eq(SmsAssetFixedRepairApplyGoodsDetail::getAssetGoodsId, goods.getId()))
                                    .stream()
                                    .map(SmsAssetFixedRepairApplyGoodsDetail::getAssetId)
                                    .collect(Collectors.toList());

                            SmsAssetCategoryManagement categoryManagement = smsAssetCategoryManagementMapper.selectById(goods.getAssetCategory());
                            if (categoryManagement != null) {
                                goodsDTO.setAssetCategoryName(categoryManagement.getCategoryName());
                            }
                            Integer count = smsAssetFixedStorageMapper.selectCount(new QueryWrapper<SmsAssetFixedStorage>()
                                    .lambda()
                                    .eq(SmsAssetFixedStorage::getAssetStatus,ASSET_STATUS_IN_STORAGE)
                                    .eq(SmsAssetFixedStorage::getAssetName, goods.getAssetName())
                                    .eq(SmsAssetFixedStorage::getAssetCategory, goods.getAssetCategory())
                                    .eq(SmsAssetFixedStorage::getAssetBrand, goods.getAssetBrand())
                                    .eq(SmsAssetFixedStorage::getAssetModel, goods.getAssetModel())
                                    .eq(SmsAssetFixedStorage::getAssetPrice, goods.getAssetPrice()));
                            goodsDTO.setAssetCount(count);
                            goodsDTO.setAssetAssetIdList(assetPreIdList);
                            return goodsDTO;
                        })
                        .collect(Collectors.toList());
        repairApplyDTO.setGoodsList(goodsList);
        return CommonResult.success(repairApplyDTO);
    }

    @Override
    public ResponseResult selectAllAssetFixedRepairApply(String apply_person, String apply_department, Integer pageSize, Integer pageNum) {
        List<SmsAssetFixedRepairApply> list11 = new ArrayList<>();
        QueryWrapper<SmsAssetFixedRepairApply> queryWrapper = new QueryWrapper<>();
        if (isNullOrEmpty(queryWrapper)) {
            return CommonResult.failed(CommonCodeEnum.DATA_NOT_FOUND);
        }

        if (!isNullOrEmpty(apply_person)) {
            queryWrapper.lambda().like(SmsAssetFixedRepairApply::getApplyPerson, apply_person);
        }
        if (!isNullOrEmpty(apply_department)) {
            queryWrapper.lambda().like(SmsAssetFixedRepairApply::getApplyDepartment, apply_department);
        }

        List<SmsAssetFixedRepairApply> list1 = smsAssetFixedRepairApplyMapper.selectList(queryWrapper);
        if (list1.size() == 0) {
            return CommonResult.success(list11, 0);
        }
        queryWrapper.orderByDesc("create_time");
        Page<SmsAssetFixedRepairApply> page = new Page<>(pageNum, pageSize);
        smsAssetFixedRepairApplyMapper.selectPage(page, queryWrapper);
        list11 = page.getRecords();
        int total = (int) page.getTotal();
        return CommonResult.success(list11, total);
    }

    @Override
    public ResponseResult allowRepairApply(SmsAssetFixedRepairApplyAllowVO allowVO, String user_id) {
        if (isNullOrEmpty(allowVO.getApplyId()) || isNullOrEmpty(allowVO.getDetailId())
                || isNullOrEmpty(allowVO.getProcessDetailStatus())) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        if (allowVO.getProcessDetailStatus() != ASSET_REPAIR_ALLOW_STATUS_PASS
                && allowVO.getProcessDetailStatus() != ASSET_REPAIR_ALLOW_STATUS_DENY) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
        }
        SmsAssetFixedRepairApply allowApply = smsAssetFixedRepairApplyMapper.selectById(allowVO.getApplyId());
        if (isNullOrEmpty(allowApply)) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_APPLY_NOT_EXIST));
        }
        SmsAssetFixedRepairApplyProcessDetail processDetail =
                smsAssetFixedRepairApplyProcessDetailMapper.selectOne(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                        .lambda()
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, allowVO.getApplyId())
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getId, allowVO.getDetailId())
                        .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailStatus, ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW));
        if (isNullOrEmpty(processDetail.getId()) || processDetail == null) {
            ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.ASSET_ALLOW_FAIL));
        }
        SmsAssetFixedRepairApplyProcessDetail allowDetail = new SmsAssetFixedRepairApplyProcessDetail();
        allowDetail.setId(allowVO.getDetailId());
        allowDetail.setProcessDetailStatus(allowVO.getProcessDetailStatus());
        if (!isNullOrEmpty(allowVO.getProcessDetailRemark())) {
            allowDetail.setProcessDetailRemark(allowVO.getProcessDetailRemark());
        }

        //判断审批人是否未最终维修确认人
        if (processDetail.getProcessDetailName().equals("维修最终确认人")&&allowVO.getProcessDetailStatus()==ASSET_REPAIR_ALLOW_STATUS_PASS) {
            if (isNullOrEmpty(allowVO.getApplyRepairContent()) ||
                    isNullOrEmpty(allowVO.getApplyRepairedPic()) ||
                    isNullOrEmpty(allowVO.getApplyRepairEvaluate())
                    ) {
                return CommonResult.failed(CommonCodeEnum.ASSET_REPAIR_PROCESS_FINANCE_NOT_FILL);
            }
            SmsAssetFixedRepairApply updateApplication = new SmsAssetFixedRepairApply();
            updateApplication.setId(allowVO.getApplyId());
            updateApplication.setApplyRepairContent(allowVO.getApplyRepairContent());
            updateApplication.setApplyRepairedPic(allowVO.getApplyRepairedPic());
            updateApplication.setApplyRepairEvaluate(allowVO.getApplyRepairEvaluate());
            smsAssetFixedRepairApplyMapper.updateById(updateApplication);
        }

        Date date = new Date();
        allowDetail.setEndTime(date);
        allowDetail.setAllowUserId(user_id);
        if (processDetail.getProcessDetailIsSign() == ASSET_REPAIR_BOOLEAN_TRUE) {
            if (isNullOrEmpty(allowVO.getProcessDetailSign())) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
            }
            allowDetail.setProcessDetailSign(allowVO.getProcessDetailSign());
        }

        if (processDetail.getProcessDetailIsStamp() == ASSET_REPAIR_BOOLEAN_TRUE) {
            if (isNullOrEmpty(allowVO.getProcessDetailStamp())) {
                ExceptionCast.cast(CommonResult.failed(CommonCodeEnum.INVALID_PARAM));
            }
            allowDetail.setProcessDetailStamp(allowVO.getProcessDetailStamp());
        }
        smsAssetFixedRepairApplyProcessDetailMapper.updateById(allowDetail);

        boolean is_done = false;

        //判断是否最后一个节点 是否驳回
        Integer detailCount = smsAssetFixedRepairApplyProcessDetailMapper.selectCount(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                .lambda()
                .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, allowVO.getApplyId()));
        if (detailCount.equals(processDetail.getProcessDetailSort()) || allowVO.getProcessDetailStatus() == ASSET_REPAIR_ALLOW_STATUS_DENY) {
            is_done = true;

            SmsAssetFixedRepairApply updateApply = new SmsAssetFixedRepairApply();
            updateApply.setId(allowVO.getApplyId());
            updateApply.setEndTime(date);
            updateApply.setAllowStatus(allowVO.getProcessDetailStatus());
            smsAssetFixedRepairApplyMapper.updateById(updateApply);
        }


        //流程结束并且同意，从资产库把对应的资产修改对应状态
        Date now_Date = new Date();
        //流程最后一个人审批完成并且审批通过
        if (detailCount.equals(processDetail.getProcessDetailSort()) && allowVO.getProcessDetailStatus() == ASSET_REPAIR_ALLOW_STATUS_PASS) {

                QueryWrapper<SmsAssetFixedRepairApplyGoodsDetail> queryWrapper  = new QueryWrapper<>();
                queryWrapper.lambda().eq(SmsAssetFixedRepairApplyGoodsDetail::getApplyId,allowVO.getApplyId());
                List<SmsAssetFixedRepairApplyGoodsDetail> list1 = smsAssetFixedRepairApplyGoodsDetailMapper.selectList(queryWrapper);
                for(SmsAssetFixedRepairApplyGoodsDetail goodsDetail:list1){
                    QueryWrapper<SmsAssetMyAssets> queryWrapper1  = new QueryWrapper<>();
                    queryWrapper1.lambda()
                            .eq(SmsAssetMyAssets::getAssetId,goodsDetail.getAssetId())
                            .eq(SmsAssetMyAssets::getAssetModel,ASSET_STATUS_REPAIR);
                    SmsAssetMyAssets smsAssetMyAssets = new SmsAssetMyAssets();
                    smsAssetMyAssets.setMyAssetStatus(ASSET_STATUS_BORROW);
                    smsAssetMyAssetsMapper.update(smsAssetMyAssets,queryWrapper1);
                }


            List<SmsAssetFixedRepairApplyGoods> goodsList =
                    smsAssetFixedRepairApplyGoodsMapper.selectList(new QueryWrapper<SmsAssetFixedRepairApplyGoods>()
                            .lambda()
                            .eq(SmsAssetFixedRepairApplyGoods::getApplyId, allowVO.getApplyId()));
            if (goodsList != null && goodsList.size() > 0) {
                for (SmsAssetFixedRepairApplyGoods goods : goodsList) {

                    Page<SmsAssetFixedStorage> page = new Page<>(1, goods.getAssetNum());
                    smsAssetFixedStorageMapper.selectPage(page, new QueryWrapper<SmsAssetFixedStorage>()
                            .lambda()
                            .eq(SmsAssetFixedStorage::getAssetStatus, ASSET_STATUS_BORROW)
                            .eq(SmsAssetFixedStorage::getAssetName, goods.getAssetName())
                            .eq(SmsAssetFixedStorage::getAssetCategory, goods.getAssetCategory())
                            .eq(SmsAssetFixedStorage::getAssetBrand, goods.getAssetBrand())
                            .eq(SmsAssetFixedStorage::getAssetModel, goods.getAssetModel())
                            .eq(SmsAssetFixedStorage::getAssetPrice, goods.getAssetPrice()));
                    List<SmsAssetFixedStorage> list = page.getRecords();
                    for (SmsAssetFixedStorage storage : list) {
                        SmsAssetFixedRepairApplyGoodsDetail goodsDetail = new SmsAssetFixedRepairApplyGoodsDetail();
                        goodsDetail.setAssetGoodsId(goods.getId());
                        goodsDetail.setAssetId(storage.getId());
                        goodsDetail.setApplyId(allowVO.getApplyId());
                        smsAssetFixedRepairApplyGoodsDetailMapper.insert(goodsDetail);
                        smsAssetFixedStorageMapper.updateById(storage);

                    }
                }

            }

        }
        //节点驳回 重置其余节点状态
        if (allowVO.getProcessDetailStatus() == ASSET_REPAIR_ALLOW_STATUS_DENY) {
            SmsAssetFixedRepairApplyProcessDetail updateDenyDetail =
                    new SmsAssetFixedRepairApplyProcessDetail();
            updateDenyDetail.setProcessDetailStatus(ASSET_REPAIR_ALLOW_STATUS_DENY_FINISH);
            smsAssetFixedRepairApplyProcessDetailMapper.update(updateDenyDetail, new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                    .lambda()
                    .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, allowVO.getApplyId())
                    .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailStatus, ASSET_REPAIR_ALLOW_STATUS_WAIT_ALLOW));
        }

        //消息通知
        if (is_done) {
            boolean result_status = false;
            if (allowVO.getProcessDetailStatus() == ASSET_REPAIR_ALLOW_STATUS_PASS) {
                result_status = true;
            }
            newTipsUtil.allowFinishTips(allowVO.getApplyId(), user_id, result_status);
        } else {
            SmsAssetFixedRepairApplyProcessDetail nextDetail =
                    smsAssetFixedRepairApplyProcessDetailMapper.selectOne(new QueryWrapper<SmsAssetFixedRepairApplyProcessDetail>()
                            .lambda()
                            .eq(SmsAssetFixedRepairApplyProcessDetail::getApplyId, allowVO.getApplyId())
                            .eq(SmsAssetFixedRepairApplyProcessDetail::getProcessDetailSort, processDetail.getProcessDetailSort() + 1));
            RangeTypeEnum rangeTypeEnum ;
            if(nextDetail.getProcessDetailIsApplicantEdit().equals(1)){
                rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_PERSON;
            }else{
                if (nextDetail.getProcessDetailObjectType() == ASSET_REPAIR_OBJECT_TYPE_ROLE) {
                    rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_ROLE;
                }else{
                    rangeTypeEnum = RangeTypeEnum.RANGE_TYPE_ENUM_PERSON;
                }
            }

            List<String> rangeIDList = new ArrayList<>();
            rangeIDList.add(nextDetail.getProcessDetailObjectId());
            newTipsUtil.allowContinueTips(allowVO.getApplyId(),
                    user_id,
                    rangeTypeEnum,
                    rangeIDList,
                    nextDetail.getId());
        }
        return CommonResult.success();
    }

    @Override
    public ResponseResult selectMyAsset(Integer pageSize, Integer pageNum,String user_id) {
        if(isNullOrEmpty(user_id)){
            return CommonResult.failed(CommonCodeEnum.INVALID_PARAM);
        }
        QueryWrapper<SmsAssetMyAssets> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(SmsAssetMyAssets::getUserId,user_id);
        List<SmsAssetMyAssets> list = smsAssetMyAssetsMapper.selectList(queryWrapper);
        if(isNullOrEmpty(list)||list.size()<1){
            return CommonResult.failed(CommonCodeEnum.DATA_NOT_FOUND);
        }
        Page<SmsAssetMyAssets> page = new Page<>(pageNum,pageSize);
        smsAssetMyAssetsMapper.selectPage(page,queryWrapper);
        List<SmsAssetMyAssets> list1 = page.getRecords();
        int total = (int) page.getTotal();
        return CommonResult.success(list1,total);
    }
}
